package hibernate.xml22;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class InitData {
	public static void main(String[] args){
		Session session = null;
		Transaction tx = null;
		try {
			session = HibernateUtil.getSession();
			tx = session.beginTransaction();
			
			Classes classes=new Classes();
			classes.setName("A202-1");
			session.save(classes);
			
			Student student1 =new Student();
			student1.setName("aaa");
			student1.setClasses(classes);
			session.save(student1);
			
			Student student2=new Student();
			student2.setName("bbb");
			student2.setClasses(classes);
			session.save(student2);
			
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
			tx.rollback();
		} finally {
			HibernateUtil.closeSession(session);
		}
	}
}
